var config = {
  serverHost: 'http://localhost:8088',
};

console.log('util')
console.log($);

var _util = {
  request : function(params){
    $.ajax({
      type: params.method || 'GET',
      url: params.url,
      dataType: params.dataType || 'json',
      data : params.data || '',
      success: function(res){
        if(0 === res.status){
          typeof params.success === 'function' && params.success(res.data, res.msg);

        }else if(10 === res.status){
          //未登录，进行页面跳转
          window.location.href = './account-login.html?redirect=' + encodeURIComponent(window.location.href);
        }else if(1 === res.status){
          typeof params.error === 'function' && params.error(res.data, res.msg);
        }
      },
      err: function(errMsg){
        //给出错误提示
      }
    });
  },

  doLogin: function(){
    //未登录，进行页面跳转
    window.location.href = './account-login.html?redirect=' + encodeURIComponent(window.location.href);
  },

  getServerURL: function(path){
    return config.serverHost + path;
  }

};

module.exports = _util